#include "mainmanager.h"
#include <QFileInfo>
#include <QtConcurrent>
#include <QDir>
#include <QStringList>
#include "common.h"
#include "httprequest.h"
#include "minizib.h"

MainManager::MainManager(QObject *parent)
    :QObject(parent) {
    m_httpPost = new HttpRequest();
    m_httpPost->fillDatas(HttpRequest::kDongFangCaiFuRequest, "https://qt.gtimg.cn/");
    connect(m_httpPost, &HttpRequest::signalStockInfomation, this, &MainManager::signalStockInfomation, Qt::QueuedConnection);
//    m_timer.setInterval(1000);
//    m_timer.start();
//    connect(&m_timer, &QTimer::timeout, this, [this](){
//        getStockInfo("603518");
//    });
}

MainManager::~MainManager() {
    m_httpPost->deleteLater();
}

void MainManager::quitApp()
{
    QApplication::quit();
}

void MainManager::getStockInfo(QString code)
{
    if(code.isEmpty())
        return;
    if(code.size()> 2 && (code.at(0) == '5' || code.at(0) == '6')) {
        code = "sh" + code;
    }
    else
        code = "sz" + code;
    m_httpPost->getStockInfo(code);
}

void MainManager::declareQML()
{
    qmlRegisterType<MainManager>("MainManager", 1, 0, "MainManager");
}

QString MainManager::getApplicationDirPath()
{
    return QApplication::applicationDirPath();
}

QString MainManager::getTitleName()
{
    return common::getApplicationName();
}

